#ifndef BUFFER_H
#define BUFFER_H

#define TIMER_QUEUE_SIZE	128

#define TIMER_ID_MNG_HEART_BEAT			0x1000
#define TIMER_ID_DATA_HEART_BEAT		0x1001
#define TIMER_ID_DATA_UPLOAD			0x1002
#define TIMER_ID_PENDING_CMD			0x1003
#define TIMER_ID_SYNC_FEEDBACK			0x1004
#define TIMER_ID_SYNC_FEEDBACK_F		0x1005
#define TIMER_ID_MNG_DEAD				0x1006
#define TIMER_ID_RESTART_CLI			0x1007
#define TIMER_ID_GET_STATUS				0x1008
#define TIMER_ID_DEV_DEAD				0x1009
#define TIMER_ID_DATA_DEAD				0x100a
#define TIMER_ID_RESTART_CREATE_PTHREAD 0x100b
#define TIMER_ID_RESTART_AUTH           0x100c
#define TIMER_ID_STATISTICS_INTERVAL    0x100d
#define TIMER_ID_SYSN                   0x100e
#define TIMER_ID_STATISTICS_FEEDBACK    0x100f
#define TIMER_ID_SNIFFER_DOING          0x1010
#define TIMER_ID_CMD_NO_RSP             0x1011
#define TIMER_ID_CHNG_TAC_CYCLE         0x1012
#define TIMER_ID_CFG_FB                 0x1013

#define TIMER_ID_REQUEST_BBU_STATE      0x1014  
#define TIMER_ID_REBOOT_BBU             0x1015
#define TIMER_ID_REPORT_BBU_STATE       0x1016    

#define TIMER_ID_BBU_CONFIG_CELL        0x1017
#define TIMER_ID_REPORT_LOCAL_CONFIG    0x1018    
#define TIMER_ID_MANUAL_SNF             0x1019 
#define TIMER_ID_HAS_MORE_CURRET_DATA   0x101b
#define TIMER_ID_SEND_OLD_DATA          0x101c
#define TIMER_ID_RESTART_UPGRADE_BBU    0x101d
#define TIMER_ID_BBU_POWER_CONFIG       0x101e
#define TIMER_ID_WORKPERIOD             0x101f
#define TIMER_ID_POWEROFFTM             0x1020
#define TIMER_ID_INTERNALE_HB           0x1021
#define TIMER_ID_CHECK_NETWORK          0x1022
#define TIMER_ID_UPGREAD_FAILED         0x1023

#define TIMER_ID_UPOADLIST1             0x1024
#define TIMER_ID_UPOADLIST2             0x1025
#define TIMER_ID_UPOADLIST3             0x1026
#define TIMER_ID_UPOADLIST4             0x1027
#define TIMER_ID_UPOADLIST5             0x1028

#define TIMER_ID_MAC_OLD_DATA           0x1029
#define TIMRT_ID_MAC_DATA               0x1030
#define TIMER_ID_MAC_UPOADLIST1         0x1031
#define TIMER_ID_MAC_UPOADLIST2         0x1032
#define TIMER_ID_MAC_UPOADLIST3         0x1033
#define TIMER_ID_MAC_UPOADLIST4         0x1034
#define TIMER_ID_MAC_UPOADLIST5         0x1035

#define TIMER_ID_FTP_GET_DATA           0x1036
#define TIMER_ID_FTP_UPLOAD_STATE       0x1037

#define TIMER_ID_FTP_DEVICE_LOG         0x1038 
#define TIMER_ID_LTE_POWER_ON           0x1039
#define TIMER_ID_WCDMA_POWER_ON         0x103a    
#define TIMER_ID_UDP_HEARTBEAT          0x103b      
#define TIMER_ID_MOBILE_SN_RECORD       0x103c
#define TIMER_ID_UNICOM_SN_RECORD       0x103d  

#define TIMER_ID_FTP_MAC_UPLOAD_STATE   0x103e
#define TIMER_ID_FTP_MAC_GET_DATA       0x103f

#define TIMER_ID_UDP_SN_DATA            0x1040

#define TIMER_ID_FTP_PLACE_GET_DATA     0x1041
#define TIMER_ID_FTP_COMPANY_GET_DATA   0x1042
#define TIMER_ID_FTP_DEVSTATE_GET_DATA	0x1043
#define TIMER_ID_FTP_SITESTATE_UPLOAD   0x1044
#define TIMER_ID_UDP_MAC_DATA           0x1045
#define TIMER_ID_FTP_TERMINAL_GET_DATA  0x1046
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _timer_q {
    struct _timer_q *next;
    I32 id;
    I32 timeout;
    I32 p_from;
    I32 p_socket;
    I32 p_len;
    I8 *p_data;
} TIMER_QUEUE;

I32 timer_queue_add(I32 timeout, I32 id, I32 p_f, I32 p_s, I32 p_l, I8 * p_d);
I32 timer_queue_del(I32 id);
I32 timer_queue_find(I32 id);
I32 timer_queue_update(I32 id, I32 timeout);
I32 timer_queue_timeout(I32 tick);

#define BUFFER_BLOCK_SIZE				8192
#define BUFFER_SIZE						512
#define BUF_SIZE_UPDATA					0xc800
#define FILE_BUF_LEN					0xc800  //50K


typedef struct _buf_hdr {
    struct _buf_hdr *next;
    I8 data[4];
} BUF_HDR;

I32 buf_msic_init(void);
I32 buf_msic_exit(void);
I8 *buffer_allocate();
void buffer_free(I8 * buf);

void buffer_dump_log(I8* buf, I32 buf_len, I32 level);
#ifdef __cplusplus
}
#endif
#endif
